<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();
/**
 *
 * @author RAMIANDRISOA Domoina
 * @tel 261 34 13 306 32
 * @email domoinaalivelo@gmailcom
 */

class Admin extends CI_Controller {

	function __construct()
	    {
		parent::__construct();
		$this->load->helper(array('form', 'url'));
		$this->load->library('session');
	    }

	function index()
	{
            $this->load->view('pageadmin/loginadmin');		
	}
	
	function menuhaut()
	{
		$this->load->view('pageadmin/menuhaut');				
	}
	
	function login()
	{
		$this->load->view('pageadmin/loginadmin');		
	}
	
	function listclinic()
	{
		$this->load->view('pageadmin/listclinic');		
	}

	function listpatient()
	{
		$this->load->view('pageadmin/listpatient');		
	}
	
	function listcomment()
	{
		$this->load->view('pageadmin/listcomment');		
	}
	
	function modifierDentisteClinic (){
		$id = $this->input->get('id');
		$data['result'] = $this->MAdmin->getDentisteToModif($id);
		$this->load->view('pageadmin/modifDentisteClinic', $data);			
	}
	
	function infoclinique()
	{
		$id_clinique = $this->input->get('id');
		$data['result']= $this->MAdmin->getInfoClinicId($id_clinique);
		$data['pays']= $this->MAdmin->getAllPays();
		$data['ville']= $this->MAdmin->getAllVille(1);
		$data['origine_materiaux3']= $this->MAdmin->getAllPays();
		$data['origine_materiaux2']= $this->MAdmin->getAllPays();
		$data['origine_materiaux1']= $this->MAdmin->getAllPays();
		$data['id_clinique']= $id_clinique;
		$this->load->vars($data);
		$this->load->view('pageadmin/infoclinique');		
	}
	
	function infopatient()
	{
		$id_patient = $this->input->get('id');
		$data['result']= $this->MAdmin->getInfoPatientId($id_patient);
		$data['pays']= $this->MAdmin->getAllPays();
		$data['ville']= $this->MAdmin->getAllVille(1);
		$data['id_patient']= $id_patient;
		$this->load->vars($data);
		$this->load->view('pageadmin/infopatient');		
	}
	
	function infoDemandeDevis()
	{
		$id_patient = $this->input->get('id');
		$data['result']= $this->MAdmin->getInfoDemandeDevisPatient($id_patient);
		$data['pays']= $this->MAdmin->getAllPays();
		$data['ville']= $this->MAdmin->getAllVille(1);
		$data['id_patient']= $id_patient;
		$this->load->vars($data);
		$this->load->view('pageadmin/infoDemandeDevis');		
	}
	
	function infoTarif()
	{
		$id_clinique = $this->input->get('id');
		$data['prix1']= $this->MAdmin->getAllTarifClinique($id_clinique);
		$data['id_clinique']= $id_clinique;
		$this->load->vars($data);
		$this->load->view('pageadmin/infoTarif');		
	}
	
	function infoGalImage()
	{
		$id_clinique = $this->input->get('id');
		$data['result1']= $this->MAdmin->getLogoImgPplClinique($id_clinique);
		$data['result2']= $this->MAdmin->getGalerieImageClinique($id_clinique);
		$data['result3']= $this->MAdmin->getPhotosSoinsClinique($id_clinique);
		$data['id_clinique']= $id_clinique;
		$this->load->vars($data);
		$this->load->view('pageadmin/infoGalImage');		
	}
	
	function infoEquipe()
	{
		$id_clinique = $this->input->get('id');
		$data['result']= $this->MAdmin->getAllDentiste($id_clinique);
		$data['id_clinique']= $id_clinique;
		$this->load->vars($data);
		$this->load->view('pageadmin/infoEquipe');		
	}
	
	function supprimerClinic(){
		$identification = $this->input->get('identification');
		$this->MAdmin->supprimerClinic($identification);
	}
	
	function validClinique(){
		$identification = $this->input->get('identification');
		$this->MAdmin->validClinique($identification);
	}
	
	function validPatient(){
		$identification = $this->input->get('identification');
		$this->MAdmin->validPatient($identification);
	}
	
	function validComment(){
		$identification = $this->input->get('identification');
		$this->MAdmin->validComment($identification);
	}
	
	function listClinicTriJson(){
		$id = $this->input->get('id');
		$data= $this->MAdmin->getListClinicTri($id);	
		$json = '{"aaData":'.json_encode($data).'}';
		header('Content-Type: application/json');		
		echo $json;
	}
	
	function listPatientTriJson(){
		$id = $this->input->get('id');
		$data= $this->MAdmin->getListPatientTri($id);	
		$json = '{"aaData":'.json_encode($data).'}';
		header('Content-Type: application/json');		
		echo $json;
	}
	
	function listCommentTriJson(){
		$id = $this->input->get('id');
		$data= $this->MAdmin->getListCommentTri($id);	
		$json = '{"aaData":'.json_encode($data).'}';
		header('Content-Type: application/json');		
		echo $json;
	}
	
	function supprimerPatient(){
		$identification = $this->input->get('identification');
		$this->MAdmin->supprimerPatient($identification);
	}
		
	function supprimerComment(){
		$identification = $this->input->get('identification');
		$this->MAdmin->supprimerComment($identification);
	}
	
	function supprimerGalImageClinic(){
		$identification = $this->input->get('identification');
		$this->MAdmin->supprimerGalImageClinic($identification);
	}
	
	function supprimerPhotoSoinClinic(){
		$identification = $this->input->get('identification');
		$this->MAdmin->supprimerPhotoSoinClinic($identification);
	}
	
	function supprimerLogoClinic(){
		$identification = $this->input->get('identification');
		$this->MAdmin->supprimerLogoClinic($identification);
	}
	
	function supprimerImgPplClinic(){
		$identification = $this->input->get('identification');
		$this->MAdmin->supprimerImgPplClinic($identification);
	}
	
	function supprimerDentisteClinic(){
		$identification = $this->input->get('identification');
		$this->MAdmin->supprimerDentisteClinic($identification);
	}
	
	function supprimerImgDD(){
		$identification = $this->input->get('identification');
		$id_patient = $this->input->get('id_patient');
		$this->MAdmin->supprimerImgDD($identification, $id_patient);
	}
		
	function supprimerLangue(){
		$identification = $this->input->get('identification');
		$id_patient = $this->input->get('id_patient');
		$this->MAdmin->supprimerLangue($identification, $id_patient);
	}
	
	function updateInfoClinique(){
		$id_clinique = $this->input->post('id_clinique');
		$email = $this->input->post('email');
		$mdp = $this->input->post('mdp');
		$pays = $this->input->post('pays');
		$map = $this->input->post('map');
		$ville = $this->input->post('ville');
		$nomville = $this->input->post('nomville');
		$adresse = $this->input->post('adresse');
		$code_postal = $this->input->post('code_postal');
		$nom_clinique = $this->input->post('nom_clinique');
		$surface = $this->input->post('surface');
		$fauteuil = $this->input->post('fauteuil');
		$scanner = $this->input->post('scanner');
		$prothese = $this->input->post('prothese');
		$marque_implant1 = $this->input->post('marque_implant1');
		$marque_implant2 = $this->input->post('marque_implant2');
		$marque_implant3 = $this->input->post('marque_implant3');
		$origine_materiaux1 = $this->input->post('origine_materiaux1');
		$origine_materiaux2 = $this->input->post('origine_materiaux2');
		$origine_materiaux3 = $this->input->post('origine_materiaux3');	
		$this->MAdmin->updateInfoClinique($id_clinique, $email, $mdp, $pays, $map, $ville, $adresse, $code_postal, $nom_clinique, $surface, $fauteuil, $scanner, $prothese, $marque_implant1, $marque_implant2, $marque_implant3, $origine_materiaux1, $origine_materiaux2, $origine_materiaux3);
		$this->MAdmin->updateNomVille($ville, $nomville);	
	}
	
	function updateDemandeDevisPatient(){
		$id_patient = $this->input->post('id_patient');
		$budget1 = $this->input->post('budget1');
		$budget2 = $this->input->post('budget2');
		$solution_souhaite = $this->input->post('solution_souhaite');
		$nb_traitement = $this->input->post('nb_traitement');
		$moment_soin = $this->input->post('moment_soin');
		$langue1 = $this->input->post('langue1');
		$langue2 = $this->input->post('langue2');
		$langue3 = $this->input->post('langue3');
		$this->MAdmin->updateDemandeDevisPatient($id_patient, $budget1, $budget2, $solution_souhaite, $nb_traitement, $moment_soin, $langue1, $langue2, $langue3);
	}
	
	function updateInfoPatient(){
		$id_patient = $this->input->post('id_patient');
		$email = $this->input->post('email');
		$mdp = $this->input->post('mdp');
		$pays = $this->input->post('pays');
		$ville = $this->input->post('ville');
		$nomville = $this->input->post('nomville');
		$adresse = $this->input->post('adresse');
		$code_postal = $this->input->post('code_postal');
		$civilite = $this->input->post('civilite');
		$nom = $this->input->post('nom');
		$prenom = $this->input->post('prenom');
		$date_naissance = $this->input->post('date_naissance');
		$tel_mobile = $this->input->post('tel_mobile');
		$tel_fixe = $this->input->post('tel_fixe');
		$this->MAdmin->updateInfoPatient($id_patient, $email, $mdp, $pays,  $ville, $adresse, $code_postal, $civilite, $nom, $prenom, $date_naissance, $tel_mobile, $tel_fixe);
		$this->MAdmin->updateNomVille($ville, $nomville);	
	}
	
	function updateTarifClinique(){
		$id_clinique = $this->input->post('id_clinique');
		$intitule_soin = $this->input->post('intitule_soin');
		$prix_soin = $this->input->post('prix_soin');
		$id_prixSoins = $this->input->post('id_prixSoins');
		$this->MAdmin->updateTarifClinique($intitule_soin, $prix_soin, $id_prixSoins);
	}
	
	function updateEquipeClinique(){
		$photo_dentiste = $this->input->post('photo_dentiste');
		$id_dentiste = $this->input->post('id_dentiste');
		$id_clinique = $this->input->post('id_clinique');
		$nom_dentiste = $this->input->post('nom_dentiste');
		$fonction_dentiste = $this->input->post('fonction_dentiste');
		$annee_exp1 = $this->input->post('annee_exp1');
		$annee_exp2 = $this->input->post('annee_exp2');
		$annee_exp3 = $this->input->post('annee_exp3');
		$annee_exp4 = $this->input->post('annee_exp4');
		$annee_exp5 = $this->input->post('annee_exp5');
		$annee_exp6 = $this->input->post('annee_exp6');
			if($annee_exp1=="" && $annee_exp2 != "" && $annee_exp3 !="" && $annee_exp4 != "" && $annee_exp5 !="" && $annee_exp6 !=""){
				$annee_exp1 = $annee_exp2;
				$annee_exp2 = $annee_exp3;
				$annee_exp3 = $annee_exp4;
				$annee_exp4 = $annee_exp5;
				$annee_exp5 = $annee_exp6;
				$annee_exp6 = "";
			}
			else if($annee_exp1=="" && $annee_exp2 == "" && $annee_exp3 !="" && $annee_exp4 !="" && $annee_exp5 !="" && $annee_exp6 !=""){
				$annee_exp1 = $annee_exp3;
				$annee_exp2 = $annee_exp4;
				$annee_exp3 = $annee_exp5;
				$annee_exp4 = $annee_exp6;
				$annee_exp5 = "";
				$annee_exp6 = "";
			}
			else if($annee_exp1=="" && $annee_exp2 == "" && $annee_exp3 =="" && $annee_exp4 !="" && $annee_exp5 !="" && $annee_exp6 !=""){
				$annee_exp1 = $annee_exp4;
				$annee_exp2 = $annee_exp5;
				$annee_exp3 = $annee_exp6;
				$annee_exp4 = "";
				$annee_exp5 = "";
				$annee_exp6 = "";
			}
			else if($annee_exp1=="" && $annee_exp2 == "" && $annee_exp3 =="" && $annee_exp4 =="" && $annee_exp5 !="" && $annee_exp6 !=""){
				$annee_exp1 = $annee_exp5;
				$annee_exp2 = $annee_exp6;
				$annee_exp3 = "";
				$annee_exp4 = "";
				$annee_exp5 = "";
				$annee_exp6 = "";
			}	
			else if($annee_exp1=="" && $annee_exp2 == "" && $annee_exp3 =="" && $annee_exp4 =="" && $annee_exp5 =="" && $annee_exp6 !=""){
				$annee_exp1 = $annee_exp6;
				$annee_exp2 = "";
				$annee_exp3 = "";
				$annee_exp4 = "";
				$annee_exp5 = "";
				$annee_exp6 = "";
			}
			else if($annee_exp1=="" && $annee_exp2 == "" && $annee_exp3 =="" && $annee_exp4 =="" && $annee_exp5 =="" && $annee_exp6 ==""){
				$annee_exp1 = "";
				$annee_exp2 = "";
				$annee_exp3 = "";
				$annee_exp4 = "";
				$annee_exp5 = "";
				$annee_exp6 = "";
			}
		$exp1 = $this->input->post('exp1');
		$exp2 = $this->input->post('exp2');
		$exp3 = $this->input->post('exp3');
		$exp4 = $this->input->post('exp4');
		$exp5 = $this->input->post('exp5');
		$exp6 = $this->input->post('exp6');
		if($exp1=="" && $exp2 != "" && $exp3 !="" && $exp4 != "" && $exp5 !="" && $exp6 !=""){
				$exp1 = $exp2;
				$exp2 = $exp3;
				$exp3 = $exp4;
				$exp4 = $exp5;
				$exp5 = $exp6;
				$exp6 = "";
			}
			else if($exp1=="" && $exp2 == "" && $exp3 !="" && $exp4 !="" && $exp5 !="" && $exp6 !=""){
				$exp1 = $exp3;
				$exp2 = $exp4;
				$exp3 = $exp5;
				$exp4 = $exp6;
				$exp5 = "";
				$exp6 = "";
			}
			else if($exp1=="" && $exp2 == "" && $exp3 =="" && $exp4 !="" && $exp5 !="" && $exp6 !=""){
				$exp1 = $exp4;
				$exp2 = $exp5;
				$exp3 = $exp6;
				$exp4 = "";
				$exp5 = "";
				$exp6 = "";
			}
			else if($exp1=="" && $exp2 == "" && $exp3 =="" && $exp4 =="" && $exp5 !="" && $exp6 !=""){
				$exp1 = $exp5;
				$exp2 = $exp6;
				$exp3 = "";
				$exp4 = "";
				$exp5 = "";
				$exp6 = "";
			}	
			else if($exp1=="" && $exp2 == "" && $exp3 =="" && $exp4 =="" && $exp5 =="" && $exp6 !=""){
				$exp1 = $exp6;
				$exp2 = "";
				$exp3 = "";
				$exp4 = "";
				$exp5 = "";
				$exp6 = "";
			}
			else if($exp1=="" && $exp2 == "" && $exp3 =="" && $exp4 =="" && $exp5 =="" && $exp6 ==""){
				$exp1 = "";
				$exp2 = "";
				$exp3 = "";
				$exp4 = "";
				$exp5 = "";
				$exp6 = "";
			}
		$langue1 = $this->input->post('langue1');
		$langue2 = $this->input->post('langue2');
		$langue3 = $this->input->post('langue3');
		$this->MAdmin->updateEquipeClinique($photo_dentiste, $nom_dentiste, $fonction_dentiste, $annee_exp1, $annee_exp2, $annee_exp3, $annee_exp4, $annee_exp5, $annee_exp6, $exp1, $exp2, $exp3, $exp4, $exp5, $exp6, $langue1, $langue2, $langue3, $id_dentiste);
	}
	
	function listClinicJson(){
		$data= $this->MAdmin->getAllClinic();
		$json = '{"aaData":'.json_encode($data).'}';
		header('Content-Type: application/json');		
		echo $json;
	}
	
	function listPatientJson(){
		$data= $this->MAdmin->getAllPatient();
		$json = '{"aaData":'.json_encode($data).'}';
		header('Content-Type: application/json');		
		echo $json;
	}
	
	function listCommentJson(){
		$data= $this->MAdmin->getAllComment();
		$json = '{"aaData":'.json_encode($data).'}';
		header('Content-Type: application/json');		
		echo $json;
	}
	
	function uploadimage(){
		$this->load->library('upload');
		$filename = $this->input->get('sary');
		if (!empty($_FILES[$filename]['name']))
		{
			$config['upload_path'] = 'upload/photodentiste';
			$config['allowed_types'] = 'gif|jpg|png';
			$tabfile = explode('.', $_FILES[$filename]['name']);
			$decodedData = base64_decode($filename);
			$randomName = substr_replace(sha1($decodedData), '', 12);
			echo $randomName.".".$tabfile[1];
			$config['file_name'] = $randomName;
			// Initialize config for File 
			$this->upload->initialize($config);
			// Upload file 
			 if ($this->upload->do_upload($filename))
		    {
		        $data = $this->upload->data();
		        $url = $config['upload_path']."".$_FILES[$filename]['name'];
		    }
			else
			{
				echo $this->upload->display_errors();
			}
		}
	}
}
?>